// 
// SoapTrace.Net - A soap message monitoring utility. 
// 
// Copyright (C) 2004-2009 Matthew Ward
// 
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, orViewMenuItemSeparator1
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
// 
// Matthew Ward (mrward@users.sourceforge.net)
// 

using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;

namespace SoapTrace
{
	public partial class ErrorReportUserControl : System.Windows.Forms.UserControl
	{
		/// <summary>
		/// Raised when the user clicks the details button.
		/// </summary>
		public event ExpandEventHandler Expand;

		/// <summary>
		/// Handler for the <see cref="Expand"/> event.
		/// </summary>
		public delegate void ExpandEventHandler( object sender, ExpandEventArgs e );
		
		private int BottomPanelHeight;

		/// <summary>
		/// Creates a new instance of the <see cref="ErrorReportUserControl"/>
		/// </summary>
		public ErrorReportUserControl( )
		{
			// This call is required by the Windows.Forms Form Designer.
			InitializeComponent( );

			BottomPanelHeight = BottomPanel.Height;

			this.Height = TopPanel.Height;
		}

		/// <summary>
		/// Sets the error text to be displayed.
		/// </summary>
		/// <param name="message">The error message.</param>
		/// <param name="e">The exception.</param>
		public void SetErrorText( string message, Exception e )
		{
			ErrorMessage = message;

			ErrorDetails = e.ToString( );
		}

		/// <summary>
		/// Gets or sets the error message.
		/// </summary>
		public string ErrorMessage
		{
			get
			{
				return ErrorMessageLabel.Text;
			}

			set
			{
				ErrorMessageLabel.Text = value;
			}
		}

		/// <summary>
		/// Gets or sets the detailed error message.
		/// </summary>
		public string ErrorDetails
		{
			get
			{
				return ErrorDetailsTextBox.Text;
			}

			set
			{
				ErrorDetailsTextBox.Text = value;
			}
		}

		/// <summary>
		/// Raises the <see cref="Expand"/> event.
		/// </summary>
		/// <param name="expanded">Flag indicating whether to expand
		/// or collapse.</param>
		protected virtual void OnExpand( bool expanded ) 
		{
			if( Expand != null ) 
			{
				//Invokes the delegates.
				Expand( this, new ExpandEventArgs( expanded ) );
			}
		}

		private void DetailsButtonClick(object sender, System.EventArgs e)
		{
			if( DetailsButton.Text == "Details >>" )
			{
				DetailsButton.Text = "Details <<";

				BottomPanel.Visible = true;
				Height = TopPanel.Height + BottomPanelHeight;
				BottomPanel.Height = BottomPanelHeight;

				OnExpand( true );
			}
			else
			{
				DetailsButton.Text = "Details >>";

				BottomPanel.Visible = false;
				Height = TopPanel.Height;

				OnExpand( false );
			}
		}
	}
}
